package com.example.controller;

import com.example.common.Result;
import com.example.entity.StudentInfo;
import com.example.service.StudentInfoService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学生信息前端操作接口
 **/
@RestController
@RequestMapping("/studentInfo")
public class StudentInfoController {

    @Resource
    private StudentInfoService studentInfoService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody StudentInfo studentInfo) {
        studentInfoService.add(studentInfo);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        ///studentInfoService.deleteById(id);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody StudentInfo studentInfo) {
        studentInfoService.updateById(studentInfo);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    /*@GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        StudentInfo studentInfo = studentInfoService.selectById(id);
        return Result.success(studentInfo);
    }*/

    /**
     * 根据用户ID查询
     */
    @GetMapping("/getByUserId/{userId}")
    public Result getByUserId(@PathVariable Long userId) {
        StudentInfo studentInfo = studentInfoService.selectByUserId(userId);
        return Result.success(studentInfo);
    }

    /**
     * 查询所有
     */
    /*@GetMapping("/selectAll")
    public Result selectAll(StudentInfo studentInfo) {
        List<StudentInfo> list = studentInfoService.selectAll(studentInfo);
        return Result.success(list);
    }*/

    /**
     * 分页查询
     */
    /*@GetMapping("/selectPage")
    public Result selectPage(StudentInfo studentInfo,
                           @RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<StudentInfo> page = studentInfoService.selectPage(studentInfo, pageNum, pageSize);
        return Result.success(page);
    }*/
}
